<?php

// [ 会员验证器 ]

namespace app\common\validate;
use think\Validate;

class Member extends Validate
{
    // 验证规则
    protected $rule = [
        'role'         => 'require|integer|in:1,2,3',
        'organization' => 'max:60',
        'openid'       => 'require|length:16,64',
        'mobile'       => 'require|regex:^1[34578]{1}\d{9}$',
        'new_mobile'   => 'require|regex:^1[34578]{1}\d{9}$',
        'passport'     => 'require|length:4,16',
        'password'     => 'require|length:4,16',
        'confpwd'      => 'require|length:4,16|confirm:password',
        'status'       => 'require|integer|in:0,1',
    ];

    // 错误提示
    protected $message = [
        'role.require'     => '角色必须',
        'role.integer'     => '角色必须为数字',
        'role.in'          => '角色取值范围[1|2|3]',

        'organization:max' => '投资机构名称最大长度[60]',

        'openid.require'   => 'openid必须',
        'openid.length'    => 'openid长度[16~64]',

        'mobile.require'   => '手机号必须',
        'mobile.regex'     => '手机号格式不正确',

        'new_mobile.require'   => '新手机号必须',
        'new_mobile.regex'     => '新手机号格式不正确',

        'passport.require' => '原密码必须',
        'passport.length'  => '原密码长度[4~16]',

        'password.require' => '密码必须',
        'password.length'  => '密码长度[4~16]',

        'confpwd.require'  => '确认密码必须',
        'confpwd.length'   => '确认密码长度[4~16]',
        'confpwd.confirm'  => '确认密码与密码不相同',

        'status.require'   => '状态必须',
        'status.integer'   => '状态必须为数字',
        'status.in'        => '状态取值范围[0|1]',
    ];

    // 验证场景
    protected $scene = [
        // 微信注册
        'wxRegister' => ['mobile','role','password','confpwd'],
        // 注册
        'register'   => ['mobile','role','password','confpwd'],
        // 登录
        'login'      => ['mobile','password'],
        // 微信绑定
        'wxBind'     => ['mobile','openid'],
        // 修改密码
        'updatePwd'  => ['passport','password','confpwd'],
        // 重置密码
        'resetPwd'   => ['mobile','password','confpwd'],
        // 重置手机号
        'resetMobile' => ['mobile','new_mobile'],
    ];
}
